ngx.req.read_body()
local mysql  =  require  "resty.mysql" 
local db, err  =  mysql: new ()
if  not db then
	ngx.say( " failed to instantiate mysql:  " , err)
	return 
end

db:set_timeout( 1000 )  --   1  sec

local ok, err, errno, sqlstate  =  db:connect{
	host  =   "127.0.0.1" ,
	port  =   3306 ,
	database  =   "p_com" ,
	user  =   "root" ,
	password  =   "weiming" ,
	max_packet_size  =   1024   *   1024  
}

if  not ok then
	ngx.say( " failed to connect:  " , err,  " :  " , errno,  "   " , sqlstate)
	return 
end

-- ngx.say( " connected to mysql. " )
 
sql  =   "select id,title from pce_dept" -- ..args[ " xxx " ]
res, err, errno, sqlstate  = db:query(sql)
if  not res then
	ngx.say( " bad result:  " , err,  " :  " , errno,  " :  " , sqlstate,  " . " )
	return 
end

local cjson  =  require  "cjson" 
ngx.say(cjson.encode(res))
ngx.req.read_body()
local method   = ngx.var.request_method
if method=='POST' then
	local data = ngx.req.get_body_data()
	local i=0
	i = string.find(data, '&', i+1)
	ngx.say(cjson.encode(data))
end
if (method=="GET") then
	local data=ngx.location.capture("/proxy")
	ngx.say(cjson.encode(data))
end

